import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Shapes 1.15

MainView {
    id: root
    width: 800
    height: 391

    property int selectedSubView: 1
    property int selectedLeftView: 0
    property int selectedRightView: 1
Component.onCompleted: {
    //mainLoader.visible=false;
}
onVisibleChanged: {
    if(visible)
    {
        valuePanel.startTimer()
    }
    else
    {
        valuePanel.stopTimmer()
    }
}
    LightBar {
        id: lightBar
        x: 0
        y: 0
        width: 532
        height: 36
    }
    Item {
        id: leftItem
        x: 0
        y: 40
        width: 532
        height: 349
        property int currentViewIndex: 0

        ValuePanel {
            id: valuePanel
            enabled: root.selectedLeftView === 0
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedLeftView
            index: 0
        }

        GraphPanel {
            id: graphPanel
            enabled: root.selectedLeftView === 1
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedLeftView
            index: 1
        }
    }
    /*ValuePanel
    {
        id:valuePanel
        x: 0
        y: 40
    }*/
    Button
    {
        id:btnSwitchMode
        x: 584
        y: 6
        width: 180
        height: 50
        background: Rectangle{
            border.width: btnSwitchMode.down?1: 0
            color: btnSwitchMode.down?"#FF614B": "#C070B0"
            border.color: "#F0D070"
                }

        text: qsTr("打印")
        onClicked: {
            mymodbus.printPage();
        }
//        text: qsTr("操作")
//        font.pixelSize: 25
//        palette.buttonText: "white"
//        Connections {
//            target: btnSwitchMode
//            onClicked: {
//                switch(root.selectedSubView)
//                {
//                    case 0:
//                        root.selectedSubView = 2;
//                        root.selectedLeftView = 0;
//                        root.selectedRightView = 2;
//                        btnSwitchMode.text =qsTr("计数");
//                        break;
//                    case 1:
//                        root.selectedSubView = 0;
//                        root.selectedLeftView = 0;
//                        root.selectedRightView = 0;
//                        btnSwitchMode.text =qsTr("比较");
//                        break;
//                    case 2:
//                        root.selectedSubView = 3;
//                        root.selectedLeftView = 1;
//                        root.selectedRightView = 3;
//                        btnSwitchMode.text =qsTr("图形");
//                        break;
//                    case 3:
//                        graphRightPanel.stopGraph()
//                        root.selectedSubView = 1;
//                        root.selectedLeftView = 0;
//                        root.selectedRightView = 1;
//                        btnSwitchMode.text =qsTr("操作");
//                        break;
//                    case 4:
//                        graphRightPanel.stopGraph()
//                        root.selectedSubView = 0;
//                        root.selectedLeftView = 0;
//                        root.selectedRightView = 0;
//                        btnSwitchMode.text =qsTr("比较");
//                        break;

//                }
//            }
//        }
    }

    Item {
        id: subItem0
        height: 325
        width: 253
        //anchors.left: 542
        //anchors.right: parent.right
        //anchors.top: 61
        property int currentViewIndex: 4
        x: 542
        y: 61
        ComparePanel {
            id: comparePanel
            enabled: root.selectedRightView === 0
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 0
        }
        OperationPanel {
            id: operationPanel
            enabled: root.selectedRightView === 1
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 1
        }
        CountPanel {
            id: countPanel
            enabled: root.selectedRightView === 2
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 2
        }


        GraphRightPanel {
            id: graphRightPanel
            enabled: root.selectedRightView === 3
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 3
        }
        Angle{
            id: anglePanel
            enabled: root.selectedRightView === 4
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 4
        }
    }

    Dialog {
        anchors.centerIn: parent
        id: saveWeightOKDialog
        //title: "提示"
        standardButtons: Dialog.Ok
        title:qsTr("保存成功！")
        modal: true
        closePolicy: "CloseOnEscape"
        onAccepted: saveWeightOKDialog.close()
        z:100
        //onRejected: console.log("Cancel clicked")
    }

    MyBuzyIndicator{
        anchors.centerIn: parent
        id: angleLoader
        visible:false
        z:101
    }
}
